package com.bgs.controller;


import com.bgs.annotation.NoneAuth;
import com.bgs.common.R;
import com.bgs.pojo.User;
import com.bgs.service.RolesService;
import com.bgs.service.UserService;
import com.bgs.utils.TokenHelper;
import io.swagger.annotations.ApiOperation;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 后台用户表 前端控制器
 * </p>
 *
 * @author Asia
 * @since 2021-09-14
 */
@RestController
@RequestMapping("/bgs/user")
public class UserController {
    @Autowired
    private TokenHelper tokenHelper;

    @Autowired
    private RolesService rolesService;

    @Autowired
    private UserService userService;

    @PostMapping("/convertTokenByStr")
    @NoneAuth
    @ApiOperation("根据请求对象获取userId，支撑远程调用使用")
    public String convertToken(String token) {
        String s = tokenHelper.convertTokenByStr(token);
        return s;
    }

    @PostMapping("getUserInfoByRequest")
    @NoneAuth
    @ApiOperation("根据请求对象获取userInfo，支撑远程调用使用")
    public R getUserInfoByRequest(@RequestBody String hl) {
        String s = tokenHelper.convertTokenByStr(hl);
        User user = userService.getById(Integer.parseInt(s));
        return R.ok().data("data", user);
    }

    @GetMapping("/findUser")
    @ApiOperation("全查用户")
    public R findUser() {
        return userService.findUser();
    }

    @PostMapping("/addUser")
    @ApiOperation("添加用户")
    public R addUser(@RequestBody User adduser) {
        return userService.addUser(adduser);
    }


    @GetMapping("/fourFindUsers")
    public R fourFindUsers(){
        return userService.fourFindUsers();
    }
}

